package com.example.pn;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

public class ListViewAdapter extends ArrayAdapter<CardModel> {

    private Context mcontext;
    private int mresource;


    public ListViewAdapter(@NonNull Context context, int resource, @NonNull ArrayList<CardModel> objects) {
        super(context, resource, objects);
        this.mcontext=context;
        this.mresource=resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        convertView= LayoutInflater.from(this.mcontext).inflate(this.mresource,parent,false);

        ImageView image =convertView.findViewById(R.id.image);
        TextView title =convertView.findViewById(R.id.title);
        TextView content =convertView.findViewById(R.id.content);

        image.setImageResource(getItem(position).getImage());
        title.setText(getItem(position).getTitle());
        content.setText(getItem(position).getContent());

        return convertView;
    }
}
